Return to start page
Core/General/Struct Group.j
1 library AStructCoreGeneralGroup requires AStructCoreGeneralVector, ALibraryCoreGeneralUnit
2
3 struct AGroup
4 //members
5 private AUnitVector m_units
6
7 //members
8
9 public method units takes nothing returns AUnitVector
10 return this.m_units
11 endmethod
12
13 //methods
14
15 public method fillGroup takes group whichGroup returns nothing
16 local integer i = 0
17 loop
18 exitwhen (i == this.m_units.size())
19 call GroupAddUnit(whichGroup, this.m_units[i])
20 set i = i + 1
21 endloop
22 endmethod
23
24 /**
25 * Creates a new Warcraft-3-like group from the group.
26 * @return Returns a newly created group.
27 */
28 public method group takes nothing returns group
29 local group whichGroup = CreateGroup()
30 call this.fillGroup(whichGroup)
31 return whichGroup
32 endmethod
33
34 /**
35 * Adds all units of group @param whichGroup to the group.
36 * @param destroy If this value is true group @param whichGroup will be destroyed after it has been added.
37 * @param clear If this value is true group @param whichGroup will be cleared after it has been added. This value has no effect if destroy is already true. If both parameters are false group @param whichGroup won't change. Unfortunately the method has to re-add all units (limited Warcraft 3 natives).
38 */
39 public method addGroup takes group whichGroup, boolean destroy, boolean clear returns nothing
40 local unit firstOfGroup
41 local integer i
42 loop
43 exitwhen (IsUnitGroupEmptyBJ(whichGroup))
44 set firstOfGroup = FirstOfGroupSave(whichGroup)
45 call this.m_units.pushBack(firstOfGroup)
46 call GroupRemoveUnit(whichGroup, firstOfGroup)
47 set firstOfGroup = null
48 endloop
49 call GroupClear(whichGroup)
50 if (destroy) then
51 call DestroyGroup(whichGroup)
52 set whichGroup = null
53 elseif (not clear) then
54 set i = 0
55 loop
56 exitwhen (i == this.m_units.size())
57 call GroupAddUnit(whichGroup, this.m_units[i])
58 set i = i + 1
59 endloop
60 endif
61 endmethod
62
63 public method isDead takes nothing returns boolean
64 local integer i = 0
65 loop
66 exitwhen (i == this.m_units.size())
67 if (not IsUnitDeadBJ(this.m_units[i])) then
68 return false
69 endif
70 set i = i + 1
71 endloop
72 return true
73 endmethod
74
75 public method removeAlliesOfPlayer takes player whichPlayer returns nothing
76 local player owner
77 local integer i = 0
78 loop
79 exitwhen (i == this.m_units.size())
80 set owner = GetOwningPlayer(this.m_units[i])
81 if (IsPlayerAlly(owner, whichPlayer)) then
82 call this.m_units.erase(i)
83 else
84 set i = i + 1
85 endif
86 set owner = null
87 endloop
88 endmethod
89
90 public method removeAlliesOfUnit takes unit whichUnit returns nothing
91 local player owner = GetOwningPlayer(whichUnit)
92 call this.removeAlliesOfPlayer(owner)
93 set owner = null
94 endmethod
95
96 public method removeEnemiesOfPlayer takes player whichPlayer returns nothing
97 local player owner
98 local integer i = 0
99 loop
100 exitwhen (i == this.m_units.size())
101 set owner = GetOwningPlayer(this.m_units[i])
102 if (not IsPlayerAlly(owner, whichPlayer)) then
103 call this.m_units.erase(i)
104 else
105 set i = i + 1
106 endif
107 set owner = null
108 endloop
109 endmethod
110
111 public method removeEnemiesOfUnit takes unit whichUnit returns nothing
112 local player owner = GetOwningPlayer(whichUnit)
113 call this.removeEnemiesOfPlayer(owner)
114 set owner = null
115 endmethod
116
117 public static method create takes nothing returns thistype
118 local thistype this = thistype.allocate()
119 //members
120 set this.m_units = AUnitVector.create()
121 return this
122 endmethod
123
124 public method onDestroy takes nothing returns nothing
125 //members
126 call this.m_units.destroy()
127 endmethod
128 endstruct
129
130 endlibrary